//
// Created by 10334 on 2022/9/26.
//

#include "initialize_demo_large.h"

#include "element.h"

static constexpr int n_module = 12;

vector<Node *> *demo_large::initialize_all_node(string *net_case) {
	auto all_node = new vector<Node *>;
	if (*net_case == "demo_large") {
		//initialize switch
		for (int i = 0; i < n_module; i++) {
			auto new_node = new Node(i, new string("switch"), 0, 0, nullptr);
			all_node->push_back(new_node);
		}
		//initialize module
		for (int i = n_module; i < n_module * 2; i++) {
			auto new_node = new Node(i, new string("module"), 0, 0, nullptr);
			all_node->push_back(new_node);
		}
		return all_node;
	} else {
		return nullptr;
	}
}

vector<Link *> *demo_large::initialize_all_link(string *net_case) {
	auto all_link = new vector<Link *>;
	if (*net_case == "demo_large") {
		//switch to switch
		for (int i = 0; i < 4; i++) {//0-1 1-2 2-3 3-4
			auto new_link = new Link(i, i, i + 1, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			//4-1
			auto new_link = new Link(4, 4, 1, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			//5-6
			auto new_link = new Link(5, 5, 6, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			//6-2
			auto new_link = new Link(6, 6, 2, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			//7-9
			auto new_link = new Link(7, 7, 9, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			//8-4
			auto new_link = new Link(8, 8, 4, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			//9-4
			auto new_link = new Link(9, 9, 4, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			//10-7
			auto new_link = new Link(10, 10, 7, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			//11-10
			auto new_link = new Link(11, 11, 10, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			//5-10
			auto new_link = new Link(12, 5, 10, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		//switch to node
		for (int i = 0; i < n_module; i++) {
			auto new_link = new Link(i, i, i + n_module, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		return all_link;
	} else {
		return nullptr;
	}
}

vector<Function *> *demo_large::initial_all_function(string *net_case) {
	//abandoned
	auto all_function = new vector<Function *>;
	if (*net_case == "demo_large") {
		{
			/*{
				"identifier": 0,
				"contain_task": [0,1]
			}*/
			auto new_function = new Function(0, new vector<int>({0, 1}), 0, 0);
			all_function->push_back(new_function);
		}
		return all_function;
	} else {
		return nullptr;
	}
}

vector<Task *> *demo_large::initialize_all_task(string *net_case, vector<Node *> *all_node) {
	auto all_task = new vector<Task *>;
	//abandoned
	if (*net_case == "demo_large") {
		{
			/*{
				"identifier": 0,
				"res_node": 0,
				"period": 20,
				"length": 0
			}*/
			if (*(*all_node)[0]->category == "module") {
				//角标是res_node的值
				auto new_task = new Task(0, (*all_node)[0], 20, 0, new string("undone"), -1, -1, -1);
				all_task->push_back(new_task);
			} else {
				fprintf(stderr, "Wrong! task %d is allocated to switch", 0);
			}
		}
		{
			/*{
				"identifier": 1,
				"res_node": 2,
				"period": 20,
				"length": 0
			}*/
			if (*(*all_node)[2]->category == "module") {
				//角标是res_node的值
				auto new_task = new Task(1, (*all_node)[2], 20, (0 * 10 + 2000) / 3.0, new string("undone"), -1, -1,
				                         -1);
				all_task->push_back(new_task);
			} else {
				fprintf(stderr, "Wrong! task %d is allocated to switch", 1);
			}
		}
		return all_task;
	} else {
		return nullptr;
	}
}

vector<Message *> *demo_large::initialize_all_message(string *net_case, vector<Task *> *all_task) {
	auto all_message = new vector<Message *>;
	if (*net_case == "demo_large") {
		{
			/*{
				"identifier": 0,
				"src_task": 0,
				"des_task": 1,
				"length": 5
			}*/
			auto new_message = new Message(0, 0 + n_module, 1 + n_module, 10, 5,
			                               0, new string("undone"), -1,
			                               nullptr, nullptr, -1);
			all_message->push_back(new_message);
		}
		return all_message;
	} else {
		return nullptr;
	}
}
